package com.akk.module.avs.service;

import com.akk.module.avs.entity.AvsYbAppoCard;
import com.akk.module.avs.entity.AvsYbAppoCardExample;
import com.akk.module.avs.mapper.AvsYbAppoCardMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;

@Service
public class AvsYbAppoCardService {

    @Autowired
    private AvsYbAppoCardExample appoCardExample;

    @Autowired
    private AvsYbAppoCardMapper appoCardMapper;

    public List<AvsYbAppoCard> findByParams(Map params){
        appoCardExample.clear();
        AvsYbAppoCardExample.Criteria criteria = appoCardExample.createCriteria();
        if (params.containsKey("appId"))
            criteria.andAppIdEqualTo(params.get("appId").toString());
        if (params.containsKey("status"))
            criteria.andStatusEqualTo(Integer.valueOf(params.get("status").toString()));
        if (params.containsKey("startDate") && params.containsKey("endDate"))
            criteria.andCreateDateGreaterThanOrEqualTo((Date) params.get("startDate")).andCreateDateLessThanOrEqualTo((Date) params.get("endDate"));
        return appoCardMapper.selectByExample(appoCardExample);
    }

    public AvsYbAppoCard findById(Long appoId){
        return appoCardMapper.selectByPrimaryKey(appoId);
    }

    public void save(AvsYbAppoCard appoCard){
        appoCardMapper.insert(appoCard);
    }

    public void update(AvsYbAppoCard appoCard){
        appoCardMapper.updateByPrimaryKey(appoCard);
    }

}
